package sharewithus.analyzer.dic;

import gnu.trove.list.linked.TLinkedList;

import java.util.List;

import sharewithus.analyzer.POSInf;
import sharewithus.analyzer.PartOfSpeech;


public class DicWord {
	/**
	 * 
	 */
	private static final long serialVersionUID = 3491549504448869494L;

	private int id; // 词id
	private String term; // 词文本
	private List<POSInf> posInfs; // 词的各种词性以及频率
	private PartOfSpeech taggedPOS = PartOfSpeech.UNKNOW;// 已标注的词性
	//public static final BJOWord UNKNOW_WORD;
	public static final DicWord START_WORD;
	public static final DicWord END_WORD;
	
	static{
		START_WORD = new DicWord(0,"start");
		START_WORD.getPosInfs().add(new POSInf(PartOfSpeech.START, 1, 0));
		END_WORD = new DicWord(0,"end");
		END_WORD.getPosInfs().add(new POSInf(PartOfSpeech.END, 1, 0));
	}
	
	public DicWord(int id,String term) {
		this.id = id;
		this.term = term;
		this.posInfs = new TLinkedList<POSInf>();
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getTerm() {
		return term;
	}

	public void setTerm(String term) {
		this.term = term;
	}

	public List<POSInf> getPosInfs() {
		return posInfs;
	}

	public void setPosInfs(List<POSInf> posInfs) {
		this.posInfs = posInfs;
	}

	public PartOfSpeech getTaggedPOS() {
		return taggedPOS;
	}

	public void setTaggedPOS(PartOfSpeech taggedPOS) {
		this.taggedPOS = taggedPOS;
	}

	public int getCost() {
		int cost = 0;
		for (POSInf p : this.posInfs)
			cost += p.getFreq();
		return cost;
	}

	public static DicWord getUnknowWord(){
		DicWord UNKNOW_WORD = new DicWord(0, null);
		PartOfSpeech retPOS = PartOfSpeech.UNKNOW;
		//int retWeight = 1;
		POSInf p = new POSInf(retPOS, 1, 0);
		UNKNOW_WORD.getPosInfs().add(p);
		return UNKNOW_WORD;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		result = prime * result + ((posInfs == null) ? 0 : posInfs.hashCode());
		result = prime * result
				+ ((taggedPOS == null) ? 0 : taggedPOS.hashCode());
		result = prime * result + ((term == null) ? 0 : term.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		DicWord other = (DicWord) obj;
		if (id != other.id)
			return false;
		if (posInfs == null) {
			if (other.posInfs != null)
				return false;
		} else if (!posInfs.equals(other.posInfs))
			return false;
		if (taggedPOS == null) {
			if (other.taggedPOS != null)
				return false;
		} else if (!taggedPOS.equals(other.taggedPOS))
			return false;
		if (term == null) {
			if (other.term != null)
				return false;
		} else if (!term.equals(other.term))
			return false;
		return true;
	}
}
